package com.moyu.oasys.search.controller;

import com.alibaba.nacos.api.model.v2.Result;
import com.moyu.common.core.domain.Page;
import com.moyu.common.core.domain.R;
import com.moyu.oasys.search.entity.File;
import com.moyu.oasys.search.service.IFileSearchService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 赵彦博
 * @Date 2024/12/5 9:27
 */
@RestController
@RequestMapping("/searches/files")
public class FileSearchController {

    private final IFileSearchService fileSearchService;

    public FileSearchController(IFileSearchService fileSearchService) {
        this.fileSearchService = fileSearchService;
    }

    @PostMapping("saveFile")
    public void saveFile(@RequestBody File file) {
        fileSearchService.saveFile(file);
    }

    @DeleteMapping("{id}")
    public void deleteFileById(@PathVariable Long id) {
        fileSearchService.deleteFileById(id);
    }

    @GetMapping("queryFile")
    public R<Page<File>> queryFile(@RequestParam String name, @RequestParam(defaultValue = "0") int pageNumber, @RequestParam(defaultValue = "10") int pageSize) {
        org.springframework.data.domain.Page<File> files = fileSearchService.findAllByName(name, pageNumber, pageSize);
        return R.ok(Page.of(files.getContent(), files.getTotalElements()));
    }

}
